package main;

import javax.servlet.http.HttpServletRequest;
import java.net.URL;

public class UriHelper {
    public static String getServerBaseUri(HttpServletRequest request) {
//        StringBuilder baseUrl = new StringBuilder();
//        baseUrl.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort());
//        return baseUrl.toString();
        return GlobalConfig.siteUrl;
    }

    public static String getBaseUriFromString(String src) {
        String base = "";
        try {
            URL url = new URL(src);

            base = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
        }
        catch (Exception e) {
            Logman.error(e.getStackTrace().toString());
        }

        return base;
    }
}
